package com.hhxxttxs.websocket.controller;

import com.hhxxttxs.websocket.service.MyWebSocketService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.util.Map;

@RestController
@Slf4j
@RequestMapping("/websocket")
public class WebSocketController {

    @Autowired
    private MyWebSocketService myWebSocketService;

    //1
    @RequestMapping("/testWS")
    public ModelAndView hello(Map<String, Object> map) {
        return new ModelAndView("websocket", map);
    }

    //2
    @RequestMapping("/send")
    public String sendWS() {
        myWebSocketService.sendMessage();
        return "Send message success";
    }

}
